package webdev.fragment;

import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.VideoView;
import dev.danang.R;

public class VideosFragment extends BaseFragment implements
		OnClickListener, SurfaceHolder.Callback {
	MediaPlayer mediaPlayer;
	SurfaceView surfaceView;
	SurfaceHolder surfaceHolder;
	boolean pausing = false;;
	VideoView mVideoView;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View layout = inflater.inflate(R.layout.play_video_frament, null);
		init(layout);
		setValueForMembers();
		setEventForMembers();

//		// Load data
//		if (ConnectionDetectorUtil.isConnectingToInternet(getActivity())) {
//
//		} else {
//			// show message "No network connection"
//			ToastMessageUtil.showToastLong(getActivity(), getResources()
//					.getString(R.string.message_no_network));
//		}

		return layout;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @author: Truong.le
	 * 
	 * @to do: TODO
	 * 
	 * @see webdev.fragment.BaseFragment#init(android.view.View)
	 */
	
	@Override
	protected void init(View layout) {
		// TODO Auto-generated method stub
		Button buttonPlayVideo = (Button)layout.findViewById(R.id.playvideoplayer);
        
        getActivity().getWindow().setFormat(PixelFormat.UNKNOWN);
       
        //Displays a video file.   
        mVideoView = (VideoView)layout.findViewById(R.id.videoview);
       
        
        String uriPath = "android.resource://dev.danang/"+R.raw.du_lich_da_nang;
		Uri uri = Uri.parse(uriPath);
        mVideoView.setVideoURI(uri);
        mVideoView.requestFocus();
        mVideoView.start();
		
        buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			        String uriPath = "android.resource://dev.danang/"+R.raw.du_lich_da_nang;
					Uri uri = Uri.parse(uriPath);
					  mVideoView.setVideoURI(uri);
				        mVideoView.requestFocus();
				        mVideoView.start();
				
				
			}});
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @author: Truong.le
	 * 
	 * @to do: TODO
	 * 
	 * @see webdev.fragment.BaseFragment#setValueForMembers()
	 */
	@Override
	protected void setValueForMembers() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @author: Truong.le
	 * 
	 * @to do: TODO
	 * 
	 * @see webdev.fragment.BaseFragment#setEventForMembers()
	 */
	@Override
	protected void setEventForMembers() {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @author: Truong.le
	 * 
	 * @to do: TODO
	 * 
	 * @see webdev.fragment.BaseFragment#getUrl()
	 */
	@Override
	protected String getUrl() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void onClick(View v) {

	}

	/* (non-Javadoc)
	 * @see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int)
	 */
	@Override
	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see android.view.SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder)
	 */
	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see android.view.SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)
	 */
	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}

}
